import { urlPrefix as DeptUrlPrefix } from "@/views/system/dept/api";
import {urlPrefix as menuPrefix} from "@/views/system/menu/api";
import {request} from "@/api/service";
import XEUtils from "xe-utils";
export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      width: '100%',
      height: '100%' // 表格高度100%, 使用toolbar必须设置
    },
    rowHandle: {
      edit: {
        thin: true,
        text: '编辑',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '删除',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      disabled: true,
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '35%'
    },
    columns: [
      {
        title: '配电柜名称',
        key: 'name',
        search: {
          disabled: false
        },
        form: {
          rules: [
            { required: true, message: '配电柜名称必填' }
          ],
          component: {
            placeholder: '请输入配电柜名称'
          }
        }
      },
      {
        title: '配电柜编码',
        key: 'code',
        search: {
          disabled: false
        },
        form: {
          rules: [
            { required: true, message: '配电柜编码' }
          ],
          component: {
            placeholder: '请输入配电柜编码'
          }
        }
      },
      {
        title: '所属配电室',
        key: 'dept',
        type: 'cascader',
        dict: {
          url: DeptUrlPrefix,
          cache: false,
          isTree: true,
          value: 'id', // 数据字典中value字段的属性名
          label: 'name', // 数据字典中label字段的属性名
          children: 'children', // 数据字典中children字段的属性名
          getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
            return request({ url: url, params: { limit: 999, status: 1, is_catalog: 1 } }).then(ret => {
              const responseData = ret.data.data
              return XEUtils.toArrayTree(responseData, { parentKey: 'parent', strict: true })
            })
          }
        },
        search: {
          disabled: false
        },
        form: {
          rules: [
            { required: true, message: '请选择配电室' }
          ],
          component: {
            placeholder: '请选择配电室',
            props: {
              elProps: {
                clearable: true,
                showAllLevels: false, // 仅显示最后一级
                props: {
                  checkStrictly: true, // 可以不需要选到最后一级
                  emitPath: false,
                  clearable: true
                }
              }
            }
          }
        }
      },
      {
        title: '温度报警值',
        key: 'warm_warning',
        type: 'number',
        search: {
          disabled: true
        },
        form: {
          rules: [
            { required: true, message: '请填写温度报警值' }
          ],
          component: {
            placeholder: '请填写温度报警值'
          }
        }
      },
      {
        title: '温度预警值',
        key: 'warm_early_warning',
        type: 'number',
        search: {
          disabled: true
        },
        form: {
          rules: [
            { required: true, message: '请选择温度预警值' }
          ],
          component: {
            placeholder: '请选择温度预警值'
          }
        }
      },
      {
        title: '电压阈值',
        key: 'v_early_warning',
        type: 'number',
        search: {
          disabled: true
        },
        form: {
          rules: [
            { required: true, message: '请填写电压阈值' }
          ],
          component: {
            placeholder: '请填写电压阈值'
          }
        }
      }
    ]
  }
}
